<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>将数组中值为 0 的项去掉，将不为 0 的值存入一个新的数组，生成新的数组。</title>
</head>
<body>
    <script>
        function zero(arr) {
            var newArr = [];
            for (i = 0 ; i < arr.length ; i++) {
                if (arr[i] === 0) {
                    arr.splice(i, 1);
                    i--;
                } else {
                    newArr.push(arr[i]);
                }
            }
            console.log(arr);
            return newArr;
        }
        console.log(zero([1,0,1,0,2,0,2,3,0,0,3,0,3,0]))
    </script>
</body>
</html>